import { _decorator, Component, Label, Node } from 'cc';
import { BaseComponent } from '../Manager/UIManager/BaseComponent';
import { GAME_POP, GAME_TOP, SOUND_TYPE } from '../Data/GlobalData';
import { TopPromptText } from '../Top/TopPromptText';
const { ccclass, property } = _decorator;

@ccclass('PopLevel')
/**
 * 顶部升级弹窗
 */
export class PopLevel extends BaseComponent {

    //更新金币方法
    public UpdateCoinCb: Function = null;

    //喵咪等级文字
    @property(Label)
    public CatLevelLabel: Label = null;

    //枪等级文字
    @property(Label)
    public GunLevelLabel: Label = null;

    protected OnShow(): void {
        this.UpdateInfo();
    }

    /**
     * 点击关闭按钮
     */
    private CloseClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.popManager.HidePop(GAME_POP.PopLevel)
    }

    /**
     * 点击升级猫咪
     */
    private UpdateCatClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);

        if (app.gameData.GameData.catlevel >= 5) {
            app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
            app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("喵咪等级已满");
            return;
        }

        if (app.gameData.GameData.coin < 500) {
            app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
            app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("金币不足");
            return;
        }

        app.gameData.GameData.coin -= 500;
        app.gameData.GameData.catlevel += 1;
        app.gameData.UpdateGameDateLocal()

        app.gameData.UpdateGameDateLocal();
        this.UpdateCoinCb && this.UpdateCoinCb();
        this.UpdateInfo();
    }

    /**
     * 点击升级枪
     */
    private UpdateGunClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);

        if (app.gameData.GameData.gunlevel >= 5) {
            app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
            app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("枪等级已满");
            return;
        }

        if (app.gameData.GameData.coin < 500) {
            app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
            app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("金币不足");
            return;
        }
        app.gameData.GameData.coin -= 500;
        app.gameData.GameData.gunlevel += 1;

        app.gameData.UpdateGameDateLocal();
        this.UpdateCoinCb && this.UpdateCoinCb();
        this.UpdateInfo();
    }

    /**
     * 更新信息
     */
    public UpdateInfo() {
        this.CatLevelLabel.string = app.gameData.GameData.catlevel.toString();
        this.GunLevelLabel.string = app.gameData.GameData.gunlevel.toString();
    }

    /**
     * 喵咪等级说明
     */
    private CatInstru() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
        app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("射程已增加" + (app.gameData.GameData.catlevel - 1) * 25);
    }

    /**
     * 枪等级说明
     */
    private GunInstru() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.topManager.ShowTop(GAME_TOP.TopPromptText, false);
        app.topManager.CurrentTop.getComponent(TopPromptText).UpdatePrompt("发射时间已减少" + (app.gameData.GameData.gunlevel - 1) * 0.1);
    }



}


